package com.hhit.zhgd.controller

import com.hhit.zhgd.domain.response.BaseResp
import com.hhit.zhgd.service.ZhgdConstructionKeypointsService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.multipart.MultipartFile
import java.io.IOException

@RestController
class ZhgdConstructionKeypointsController {

    @Autowired
    private val zhgdConstructionKeypointsService: ZhgdConstructionKeypointsService? = null


    @PostMapping("/importConstructionKeypoints")
    @Throws(Exception::class)
    fun importConstructionKeypoints(@RequestParam("file") multipartFile: MultipartFile?): BaseResp<Any?>? {
        return zhgdConstructionKeypointsService?.importConstructionKeypoints(multipartFile)
    }

    /**
     * @描述 质量管理-获取标准工艺和施工要点信息
     * @参数 []
     * @返回值 com.hhit.zhgd.utils.R
     * @创建人 qianchengcheng
     * @创建时间 2023/5/28
     * @修改人和其它信息
     */
    @GetMapping("/getConstructionKeypointsInfo")
    fun getConstructionKeypointsInfo(): BaseResp<Any?>? {
        return BaseResp.success(zhgdConstructionKeypointsService?.getConstructionKeypointsInfo())
    }

    /**
     * @描述 导入标准工艺视频
     * @参数 [multipartFile, id]
     * @返回值 com.hhit.zhgd.utils.R
     * @创建人 qianchengcheng
     * @创建时间 2023/5/28
     * @修改人和其它信息
     */
    @PostMapping("/importStandardTechnologyVideo")
    @Throws(IOException::class)
    fun importStandardTechnologyVideo(
        @RequestParam("file") multipartFile: MultipartFile?,
        @RequestParam("id") id: Int?
    ): BaseResp<Any?>? {
        return zhgdConstructionKeypointsService?.importStandardTechnologyVideo(multipartFile, id)
    }

    /**
     * @description 后台管理-安全质量-新增标准工艺
     * @author qianchengcheng
     * @date 2024/7/24 11:14
     */
    @PostMapping("backStage/addConstructionKeypoints")
    fun addConstructionKeypoints(@RequestParam("file") file: MultipartFile?): BaseResp<Any?>? {
        return try {
            zhgdConstructionKeypointsService?.addConstructionKeypoints(file)
        } catch (e: Exception) {
            BaseResp.fail("添加异常!" + e.message)
        }
    }

    /**
     * @description 后台管理-安全质量-分页查询标准工艺
     * @author qianchengcheng
     * @date 2024/7/24 13:45
     */
    @GetMapping("backStage/getConstructionKeypointsPageInfo")
    fun getConstructionKeypointsPageInfo(
        @RequestParam("keyWord") keyWord: String?,
        @RequestParam(value = "page", defaultValue = "1") page: Int,
        @RequestParam(value = "size", defaultValue = "15") size: Int
    ): BaseResp<Any?>? {
        return BaseResp.success(zhgdConstructionKeypointsService?.getConstructionKeypointsPageInfo(keyWord, page, size))
    }

    /**
     * @description 后台管理-安全质量-删除标准工艺
     * @author qianchengcheng
     * @date 2024/7/24 15:41
     */
    @GetMapping("backStage/delConstructionKeypoints")
    fun delConstructionKeypoints(@RequestParam("id") id: Int?): BaseResp<Any?>? {
        return zhgdConstructionKeypointsService?.delConstructionKeypoints(id)
    }
}